﻿
#Const xhtmlversion = "1.1"

Imports System.IO
Imports xmlctrl
Imports xhtmlctrl

Public Class xhtmlpage
#If xhtmlversion = "1.0" Then
    inherits xmlpage_1_0 
#Else
    Inherits xmlpage_1_1
#End If

    Private _begin As container = Nothing
    Private _backgroundDownloader As backgroundDownloader = Nothing
    Private _html As html = Nothing
    Private _head As head = Nothing
    Private _body As body2 = Nothing
    Private _title As title = Nothing
    Private _inlineScript As inlineScript = Nothing
    Private _inlineStyle As inlineStyle = Nothing
    Private _endInlineScript As inlineScript = Nothing

    Private _footer As div = Nothing

    Public Function inlineScript() As inlineScript
        assert(Not _inlineScript Is Nothing, "_inlineScript is nothing.")
        Return _inlineScript
    End Function

    Public Function inlineStyle() As inlineStyle
        assert(Not _inlineStyle Is Nothing, "_inlineStyle is nothing.")
        Return _inlineStyle
    End Function

    Public Function endInlineScript() As inlineScript
        assert(Not _endInlineScript Is Nothing)
        Return _endInlineScript
    End Function

    Public Function beginPlace() As container
        assert(Not _begin Is Nothing)
        Return _begin
    End Function

    Public Function backgroundDownloader() As backgroundDownloader
        assert(Not _backgroundDownloader Is Nothing)
        Return _backgroundDownloader
    End Function

    Public Function html() As html
        assert(Not _html Is Nothing, "_html is nothing.")
        Return _html
    End Function

    Public Function head() As head
        assert(Not _head Is Nothing, "_head is nothing.")
        Return _head
    End Function

    'override original body to div, as w3 standard
    'Public Function body() As body
    '    assert(Not _body Is Nothing, "_body is nothing.")
    '    Return _body
    'End Function

    Public Function body() As body2
        assert(Not _body Is Nothing, "_body is nothing.")
        Return _body
    End Function

    Public Function title() As title
        assert(Not _title Is Nothing, "_title is nothing.")
        Return _title
    End Function

    Public Function footer() As div
        If _footer Is Nothing Then
            _footer = New div(output())
            body().addchildtobody(_footer)
        End If

        Return _footer
    End Function

    Public Sub addcsslink(ByVal link As String)
        Dim csslink As csslink = Nothing
        csslink = New csslink(output())
        csslink.href = link
        head().addchild(csslink)
    End Sub

    Public Sub addjsscript(ByVal link As String)
        Dim script As script = Nothing
        script = New script(output())
        script.src = link
        script.text = " "
        script.type = network.http.contentType.textjavascript
        head().addchild(script)
    End Sub

    Public Sub New(Optional ByVal buff As Stream = Nothing)
        MyBase.New(buff)

        Dim doctype As doctype = Nothing
        doctype = New doctype(buff)
        MyBase.addchild(doctype)

        _begin = New container()
        MyBase.addchild(beginPlace())

        _backgroundDownloader = New backgroundDownloader(Me, buff)
        beginPlace().addchild(_backgroundDownloader)

        _html = New html(buff)
        html().xml_lang = "en"
        MyBase.addchild(html())

        _head = New head(buff)
        html().addchild(head())

#If CANNOTDETERMINE Then
        Dim meta As meta = Nothing
        meta = New meta(buff)
        meta.http_equiv = "Content-Type"
        meta.content = network.http.contentType.texthtmlUtf8
        head().addchild(meta)
#End If

        _body = New body2(buff)
        html().addchild(body())

        _title = New title(buff)
        head().addchild(title())

        _inlineScript = New inlineScript(buff)
        head().addchild(inlineScript())

        _inlineStyle = New inlineStyle(buff)
        head().addchild(inlineStyle())

        _endInlineScript = New inlineScript(buff)
        html().addchild(endInlineScript())
    End Sub
End Class
